package com.xbongbong.saas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;

/**
 * @author: yingjf
 * @date: 2022/10/20 18:28
 * @description:竞争对手错误枚举
 */
public enum CompetitorErrorCodeEnum {
    // 未知错误
    API_ERROR_UNKNOWN(404404, "enum.errorCode.msg.api_error_unknown"),

    // 竞争对手
    API_ERROR_330001(330001, "enum.errorCode.msg.api_error_330001"),
    API_ERROR_330002(330002, "enum.errorCode.msg.api_error_330002"),
    API_ERROR_330003(330003, "enum.errorCode.msg.api_error_330003"),

    ;
    /**
     * 枚举值--错误码--
     */
    private final int code;

    /**
     * 错误信息--错误描述
     */
    private final String msg;

    /**
     * 构造一个<code>ErrorCodeEnum</code>枚举对象
     *
     * @param code 错误码
     * @param msg  错误描述
     */
    CompetitorErrorCodeEnum(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public int getCode() {
        return code;
    }

    public String getMsg() {
        return I18nMessageUtil.getMessage(msg);
    }

    /**
     * 通过枚举<code>code</code>获得枚举
     *
     * @param code 错误码
     * @return ErrorCodeEnum
     */
    public static CompetitorErrorCodeEnum getByCode(Integer code) {
        for (CompetitorErrorCodeEnum cacheCode : values()) {
            if (code.equals(cacheCode.getCode())) {
                return cacheCode;
            }
        }
        return API_ERROR_UNKNOWN;
    }

}
